package com.jason.bookworm.service.impl;

import com.jason.bookworm.dao.pojo.Feedback;
import com.jason.bookworm.response.Result;
import com.jason.bookworm.response.StatusEnum;
import com.jason.bookworm.service.FeedbackService;
import com.jason.bookworm.service.HandleFeedbackService;
import com.jason.bookworm.utils.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HandleFeedbackServiceImpl implements HandleFeedbackService {

    @Autowired
    private FeedbackService feedbackService;

    /**
     * @return 所有反馈
     */
    @Override
    public Result<List<Feedback>> getAllFeedback() {
        //获取用户名
        String username = LoginUserUtil.getCurrentUsername();
        //获取反馈
        List<Feedback> feedbackList = feedbackService.getAllFeedback(username);
        if (feedbackList.isEmpty()) {
            return new Result<>(StatusEnum.GET_ERR, "反馈列表为空！");
        }
        return new Result<>(StatusEnum.GET_OK, feedbackList);
    }

    /**
     * @param feedback 反馈记录
     * @return 添加结果
     */
    @Override
    public Result<Object> addOneFeedback(Feedback feedback) {
        //获取用户名
        String username = LoginUserUtil.getCurrentUsername();
        feedback.setUsername(username);
        //添加反馈
        feedbackService.save(feedback);
        return Result.getResult(StatusEnum.POST_OK);
    }
}
